import type { Directive, App } from 'vue'

interface DirectiveObj {
  default: Directive
}

const directive = import.meta.glob<DirectiveObj>('./*.ts', {
  eager: true
})

const directiveInstance = {
  install(app: App<Element>) {
    Object.entries(directive).forEach(([path, directive]) => {
      const directiveName = path.match(/\.\/(\w+)\.ts$/)?.[1]

      if (!directiveName || directiveName.startsWith('index')) return
      app.directive(directiveName, directive.default)
      console.log(directiveName, directive.default)
    })
  }
}

export default directiveInstance
